<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>身高预测</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #000000; 
            margin: 0;
            padding: 0;
        }

        #div1 {
            height: auto;
            width: 90%;
            max-width: 500px;
            margin: 50px auto;
            text-align: center;
            background-color: #fdfdfd; 
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        }

        h3 {
            color: #57223c; /* 粉色标题 */
        }

        input[type="text"] {
            margin: 10px 0;
            padding: 10px;
            border: 1px solid #ad8197; /* 粉色边框 */
            border-radius: 5px;
            width: 80%;
        }

        input[type="button"] {
            background-color: #5a6d74; /* 浅蓝色按钮 */
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 5px;
            cursor: pointer;
            margin: 5px;
            transition: background-color 0.3s;
        }

        input[type="button"]:hover {
            background-color: #1e99ca; /* 浅蓝色按钮悬停效果 */
        }

        #result {
            margin-top: 20px;
            font-size: 20px;
            color: #9c0757; /* 深粉色 */
        }

        .footer {
            margin-top: 30px;
            font-size: 14px;
            color: #666;
        }
    </style>
    <script>
        function validateInput(height) {
            // 验证输入是否为数字且大于等于50
            const value = parseFloat(height);
            if (isNaN(value) || value < 50) {
                alert("输入的身高必须是数字且大于50厘米，请仔细检查");
                return false;
            }
            return true;
        }

        function kaishijisuan() {
            var father_height = document.getElementById("father_height").value;
            var mother_height = document.getElementById("mother_height").value;

            // 验证输入，确保两个文本框都填写
            if (father_height === "" && mother_height === "") {
                alert("请分别输入父亲和母亲的身高。");
                return;
            } else if (father_height === "") {
                alert("请输入父亲的身高。");
                return;
            } else if (mother_height === "") {
                alert("请输入母亲的身高。");
                return;
            }

            // 验证父亲和母亲的身高输入
            if (!validateInput(father_height) || !validateInput(mother_height)) {
                return;
            }

            father_height = parseFloat(father_height);
            mother_height = parseFloat(mother_height);
            var gender = document.getElementsByName("gender");
            var result = 0;

            for (var i = 0; i < gender.length; i++) {
                if (gender[i].checked) {
                    if (gender[i].value == "male") {
                        result = (father_height + mother_height) / 2 * 1.08;
                    } else if (gender[i].value == "female") {
                        result = (father_height * 0.923 + mother_height) / 2;
                    }
                }
            }

            result = result.toFixed(1);
            document.getElementById("result").innerHTML = "您的儿童身高为：" + result + "厘米(CM)";
        }

        function chongxinjisuan() {
            document.getElementById("father_height").value = "";
            document.getElementById("mother_height").value = "";
            document.getElementsByName("gender")[0].checked = true;
            document.getElementsByName("gender")[1].checked = false;
            document.getElementById("result").innerHTML = "";
        }
    </script>
</head>

<body>
    <div id="div1">
        <h3>身高预测</h3>
        <hr>
        <h3>儿童身高计算</h3>
        父亲身高：
        <input type="text" id="father_height" placeholder="请输入父亲身高"> 厘米(CM) <br>
        母亲身高：
        <input type="text" id="mother_height" placeholder="请输入母亲身高">厘米(CM)<br>
        儿童性别：
        <input type="radio" name="gender" value="male" checked>男
        <input type="radio" name="gender" value="female">女<br>
        <input type="button" value="开始计算" onclick="kaishijisuan()">
        <input type="button" value="重新计算" onclick="chongxinjisuan()"><br>
        测试结果：<span id="result"></span>
        <div class="footer">©2024 版权由@Z-NM-0提供</div>
    </div>
</body>

</html>
